import sweetII;

# Extend the function

class PectinFetcher (sweetII.SweetII):
	def seq_to_sweetII(seq):
		"""Turns the pectin sequence passed into a Sweet II command seq."""
		
		seqdict = { 'G' : "a-D-GalpA",
					'E' : "a-D-GalpA6Me"
				 };

		linkseq = "-(1-4)-";

		sweetstr = "";

		for c in seq:
			if sweetstr != "":
				sweetstr += linkseq;

			sweetstr += seqdict[c];
		return sweetstr;
	
		
	seq_to_sweetII = staticmethod(seq_to_sweetII);
	
	def fetch_pectin_seq(self, seq):
		# Expects a G/E sequence to fetch and saves it to 'seq.pdb' in the cwd.
	
		# First turn the sequence into a sweet II command
		sweetII = PectinFetcher.seq_to_sweetII(seq);

		# Now fetch it
		res = self.gen_sweet_with_linucs(sweetII);

		# And save the pdb file
		f = open(seq + '.pdb', 'w');
		f.write(res.pdb);
		f.close();